app.views.NewItemView = Ext.extend(Ext.form.FormPanel, {
	dockedItems: [{
		title: 'Add New Item',
		xtype: 'toolbar',
		items: [
			{
				id: 'cancelNew',
				text : 'back',
				ui: 'back',
				listeners: {
					'tap': function() {
						Ext.dispatch({
							controller: app.controllers.ListController,
							id: this.liId,
							action: 'displayDetail',
							animation: {type: 'slide', direction: 'right'}
						});
					}
				}
			},
			
			{xtype: 'spacer'},

			
			{
				id: 'done',
				text : 'save',
				listeners: {
					'tap': function() {
					
						var liId = this.liId;
												
						var newItem = app.views.NewItemView.getValues().item;
						
						if (newItem) {
								var parameters = {
									liId: liId,
									item: newItem
								};
								
								var rcds = [];
								rcds.push(parameters);
								
								var operation = new Ext.data.Operation({
									action: 'createNewItem',
									records: rcds
								});
								
								var theProxy = app.stores.checkLists.getProxy();
								
								theProxy.update(operation, null, null);
						
						}
						
						app.views.NewItemView.reset();
						
						Ext.dispatch({
							controller: app.controllers.ListController,
							id: liId,
							action: 'displayDetail',
							animation: {type: 'slide', direction: 'right'}
						});
					}
				}
			}
		]
		
	}],
	
	submitOnAction: false,
	
	items: [
		{
			name: 'item',
			label: 'Item',
			xtype: 'textareafield',
			maxRows: 5,
			maxLength: 128
		}
			
	],	
	
			
	prepCache: function(liId) {
	
		var record = app.stores.checkLists.getById(liId);
		
		var toolbar = this.getDockedItems()[0];
		toolbar.getComponent('cancelNew').liId = liId;	
		toolbar.getComponent('done').liId = liId;	
		
		toolbar.setTitle(record.get('listName'));
		
		this.record = record;
		
	}
});
